package com.example.njut;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

import javax.security.auth.login.LoginException;

public class WelcomeActivity extends AppCompatActivity {
    private TextView timeover;
    Timer timer = new Timer();
    int num = 6;
    private RelativeLayout adBg;



    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        //多线程
        timeover = (TextView) findViewById(R.id.timeover);
        adBg = (RelativeLayout) findViewById(R.id.ad_bg);

        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        num--;
                        timeover.setText("倒计时："+num+"秒"+"\n跳过");
                        if(num<1){
                            timer.cancel();
                            Intent intent =new Intent();
                            intent.setClass(WelcomeActivity.this, LoginActivity.class);
                            startActivity(intent);
                            WelcomeActivity.this.finish();
                        }
                    }
                });
            }
        };
        timer.schedule(task,1000,1000);
        timeover.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent();
                intent.setClass(WelcomeActivity.this,LoginActivity.class);
                startActivity(intent);
                WelcomeActivity.this.finish();
            }
        });
        //点广告跳转其他页面
        adBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent= new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse("https://ow.blizzard.cn/home");
                intent.setData(content_url);
                startActivity(intent);
                WelcomeActivity.this.finish();
            }
        });
    }
}
